/**
 * @param {number[]} prices
 * @return {number}
 */
var maxProfit = function(prices) {
  let result = 0
  let dp = []
  let buy = 0

  for(let i = 0; i < prices.length; i++) {
    let num = prices[i]
    if (buy === 0) {
      buy = num
      dp[i] = -buy
    } else {
      if (buy - num) {
        dp[i] = buy - num
        
      }
    }
    
  }

  return result
};